package com.heima.article.controller.v1;

import com.heima.article.mapper.ArticleMapper;
import com.heima.article.service.ArticleService;
import com.heima.common.constants.ArticleConstants;
import com.heima.model.article.dtos.ArticleHomeDto;
import com.heima.model.article.dtos.ArticleInfoDto;
import com.heima.model.article.pojos.ApArticle;
import com.heima.model.article.vos.ArticleBehaviorVO;
import com.heima.model.common.dtos.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.List;

/**
 * @author brianxia
 * @version 1.0
 * @date 2022-11-10 11:33
 */
@RestController
@RequestMapping("/api/v1/article")
public class ArticleController {

    @Autowired
    private ArticleService articleService;

    @PostMapping("/load")
    public ResponseResult load(@RequestBody ArticleHomeDto dto){
        List<ApArticle> list = articleService.load(dto,null); //null代表加载默认10条
        return ResponseResult.okResult(list);
    }

    @PostMapping("/loadmore")
    public ResponseResult loadmore(@RequestBody ArticleHomeDto dto){
        List<ApArticle> list = articleService.load(dto, ArticleConstants.LOADTYPE_LOAD_MORE); //1代表加载更多
        return ResponseResult.okResult(list);
    }

    @PostMapping("/loadnew")
    public ResponseResult loadnew(@RequestBody ArticleHomeDto dto){
        List<ApArticle> list = articleService.load(dto,ArticleConstants.LOADTYPE_LOAD_NEW); //2代表加载更新
        return ResponseResult.okResult(list);
    }

    @Autowired
    private ArticleMapper articleMapper;

    @GetMapping("/test")
    public void test(){
        articleMapper.updateLikes(1592713800342179842L);
    }


    @PostMapping("/load_article_behavior")
    public ResponseResult loadArticleBehavior(@Valid @RequestBody ArticleInfoDto dto){
        ArticleBehaviorVO vo = articleService.loadArticleBehavior(dto);

        return ResponseResult.okResult(vo);
    }
}
